import Vue from 'vue'
import Router from 'vue-router'
import MenuRouter from './menuRouter'
import { checkLogin ,clearCookie} from '@/common/index'
import {getStore} from "../common";
import de from "element-ui/src/locale/lang/de";

Vue.use(Router);
var clientIp = getStore('clientIp');

const localRoutes = [
    {
        path: '/',
        redirect:clientIp === '192.168.1.6'?'/LargeScreen':clientIp === '192.168.1.7'?'/SmallScreen':'/login'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/Login.vue')
    },
    {
        path: '/SmallScreen',
        name: 'SmallScreen',
        component: () => import('@/views/SmallScreen.vue')
    },
    {
        path: '/LargeScreen',
        name: 'LargeScreen',
        component: () => import('@/views/LargeScreen.vue')
    },
    {
        path: '/BDUHome',
        name: 'BDUHome',
        component: () => import('@/layout/BDU_test_system/Home.vue'),
        meta:{
            keepAlive:true
        }
    },
    {
        path: '/BDUTester',
        name: 'BDUTester',
        component: () => import('@/layout/BDU_test_system/Index.vue')
    },
    {
        path: '/BDUManual',
        name: 'BDUManual',
        component: () => import('@/layout/BDU_test_system/BDUManual.vue')
    },
    {
        path: '/home',
        name: 'home',
        children: MenuRouter,
        component: () => import('@/layout/mainControl/Index.vue')
    },
    {
        path:'/workStationOperator',
        name:'workStationOperator',
        meta:{},
        component:()=>import('@/layout/workStationOperator/Index.vue')
    },
    {
        path:'/WorkStationManager',
        name:'workStationManager',
        meta:{},
        component:()=>import('@/layout/workStationManager/Index.vue')
    },
    {
        path: '/noAuth',
        name: 'noAuth',
        meta: {

        },
        component: () => import('@/views/NoAuth.vue')
    },
    {
      path:'*',
      name: 'noAuth',
      meta: {

      },
      component: () => import('@/views/NoAuth.vue')
    }
];

const router = new Router({
    routes: [
        ...localRoutes
    ]
})

const VueRouterPush = Router.prototype.push;
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
};
// router.beforeEach((to, form, next) => {
//     if(to.path == '/login'){
//         if(checkLogin()){
//             clearCookie('Sw.WorkLine.Http.Api')
//         }else{
//             next()
//         }
//     }else{
//         if(checkLogin()){
//             next()
//         }else{
//             next('/login')
//         }
//     }
// });

export default router;

